package com.lzh.farmersshop.controller.admin;


import com.lzh.farmersshop.util.Result;
import lombok.extern.slf4j.Slf4j;
import com.lzh.farmersshop.entity.Order;
import com.lzh.farmersshop.service.OrderService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

import static com.lzh.farmersshop.util.Result.failure;

/**
 * (Order)表控制层
 *
 * @author makejava
 * @since 2024-01-04 15:41:50
 */
@Slf4j
@RestController
@RequestMapping("admin/order")
@Transactional(rollbackFor = Exception.class)
public class OrderController {
    /**
     * 服务对象
     */
    @Resource
    private OrderService orderService;

    /**
     * 分页查询所有数据
     *
     * @param order 查询实体
     * @return 所有数据
     */
    @GetMapping("selectAll")
    public Result selectAll(Order order,Integer page,Integer limit) {
        if (limit == null || page == null) {
            return Result.failure("limit和page不能为空");
        }
        return orderService.selectAll(order, page, limit);
    }

    /**
     * 修改数据
     *
     * @param order 实体对象
     * @return 修改结果
     */
    @PostMapping("update")
    public Result update(Order order) {
        //判断order是否为空,为空直接返回
        if (order==null){
            return Result.success("订单参数不能为空！！！");
        }

        order.setFhtime(new Date());

        if (orderService.updateById(order)){
            return Result.success("发货成功！！！");
        }
        return failure("发货失败！！！");
    }
}

